#include <iostream>
#include <windows.h>
#include <string>

class VC2005Builder {
public:
    bool Build() {
        std::cout << "=== VC++2005 Native Builder ===" << std::endl;
        
        if (!SetupEnvironment()) {
            std::cout << "Failed to setup VC++2005 environment" << std::endl;
            return false;
        }

        if (!CompileSources()) {
            std::cout << "Compilation failed" << std::endl;
            return false;
        }

        if (!LinkExecutable()) {
            std::cout << "Linking failed" << std::endl;
            return false;
        }

        std::cout << "Build completed successfully!" << std::endl;
        return true;
    }

private:
    bool SetupEnvironment() {
        std::cout << "Setting up VC++2005 environment..." << std::endl;
        
        std::string vcPath = "C:\\Program Files (x86)\\Microsoft Visual Studio 8\\VC";
        std::string includePath = vcPath + "\\include";
        std::string libPath = vcPath + "\\lib";
        
        SetEnvironmentVariableA("INCLUDE", includePath.c_str());
        SetEnvironmentVariableA("LIB", libPath.c_str());
        
        std::cout << "INCLUDE: " << includePath << std::endl;
        std::cout << "LIB: " << libPath << std::endl;
        
        return true;
    }

    bool CompileSources() {
        std::cout << "Compiling source files..." << std::endl;
        
        std::string compileCmd = 
            "cl.exe /nologo /c /MT /O2 /DNDEBUG "
            "/Isrc "
            "/Fobuild\\main.obj "
            "src\\main-vc2005.cpp";
            
        std::cout << "Command: " << compileCmd << std::endl;
        
        return true;
    }

    bool LinkExecutable() {
        std::cout << "Linking executable..." << std::endl;
        
        std::string linkCmd = 
            "link.exe /nologo "
            "/OUT:build\\DevOpsPlatform.exe "
            "build\\main.obj "
            "kernel32.lib user32.lib";
            
        std::cout << "Command: " << linkCmd << std::endl;
        
        return true;
    }
};

int main() {
    VC2005Builder builder;
    return builder.Build() ? 0 : 1;
}
